<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/x-template" id="addnewss">
    <div id="addnews">
        <div class="content">
            <div class="my-box">
                <div class="title">
                    <span>标题<em>*</em></span>
                    <input type="text" v-model="title">
                </div>
                <div class="abstract">
                    <span>摘要</span>
                    <textarea v-model="summary"></textarea>
                </div>
                <div class="author">
                    <span>作者<em>*</em></span>
                    <input type="text" v-model="author">
                </div>
            </div>
            <div class="kingeditor">
                <span style="font-size: 18px">内容<em style="color:red">*</em></span>
                <div id="editor"></div>
            </div>
        </div>
        <div class="submit" @click="submit()">
            发布内容
        </div>
    </div>
</script>
<script>
    var aaa = {
        template: '#addnewss',
        data: function() {
            return {
                category: '',
                title: "",
                summary: "",
                author: "",
                content: "",
                thisPage: ""
            }
        },
        ready : function () {
            var thisUrl = window.location.href.split('.jsp');
            var thisaa = thisUrl[0].substr(thisUrl[0].length-4);
            this.thisPage = thisaa + ".jsp";
            $('#editor').summernote({
                lang: 'zh-CN',
                height: 400
            });
            $("body").on("change", ".note-image-input", function(event){
                var files = event.target.files ;
                window.tempfiles = files ;
                for(var i=0;i<files.length;i++){
                    if(files[i].size>1024*1024*5){            //改了富文本插件的3111行
                        this.danger("图片大小不能超过5M!")
                    }
                }
            }.bind(this))
        },
        methods: {
            submit: function() {
                var _this = this;
                var content = $('#addnews .note-editable').html();
                _this.content = content;
                if($.trim(_this.title) == "") {
                    layer.open({
                        title: '提示',
                        content: '标题不能为空!'
                    })
                } else if($.trim(_this.title).length > 100){
                    layer.open({
                        title: '提示',
                        content: '标题不能超过100个字!'
                    })
                } else if($.trim(_this.summary).length > 200) {
                    layer.open({
                        title: '提示',
                        content: '摘要不能超过200个字!'
                    })
                } else if($.trim(_this.author) == "") {
                    layer.open({
                        title: '提示',
                        content: '作者不能为空!'
                    })
                } else if($.trim(_this.author).length > 100) {
                    layer.open({
                        title: '提示',
                        content: '作者不能超过100个字!'
                    })
                } else if (/^(<p>(<br>)*|(&nbsp;\s*)*<\/p>)*$/.test(_this.content)) {
                    layer.open({
                        title: '提示',
                        content: '内容不能为空!'
                    })
                } else if($.trim(_this.content).length > 10000) {
                    layer.open({
                        title: '提示',
                        content: '内容不能超过10000字!'
                    })
                } else {
                    eeesysLoading();
                    $.ajax({
                        type: 'POST',
                        url: _this.thisPage,
                        data: {
                            act: "add_news",
                            hospital: "1070",
                            labelId: _this.category,
                            title: _this.title,
                            author: _this.author,
                            summary: _this.summary,
                            content: _this.content
                        },
                        success: function (res) {
                            _this.title = "";
                            _this.author = "";
                            _this.summary = "";
                            _this.content = "";
                            $('#addnews .note-editable').html("");
                            eeesysLoadingCancel();
                            //console.log(res);
                            res = JSON.parse(res);
                            if(res.errcode == 0) {
                                layer.open({
                                    title: '提示',
                                    content: '添加成功!',
                                    yes: function(index, layero) {
                                        _this.$dispatch('addSucc');
                                        layer.close(index);
                                    }
                                })
                            } else {
                                layer.open({
                                    title: '提示',
                                    content: res.errmsg
                                })
                            }
                        }
                    })
                }
            }
        },
        events: {
            getCategory: function(num) {
                this.category = num;
                //console.log(this.category);
            }
        }
    }
    $('body').on('click',"#addnews .note-btn.btn.btn-default.btn-sm.dropdown-toggle[data-original-title='样式']",function() {
        $('.dropdown-menu.dropdown-style').show();
    });
    $('body').on('click',"#addnews .note-btn.btn.btn-default.btn-sm.dropdown-toggle[data-original-title='段落']",function() {
        $(this).next().show();
    });
    $('body').on('click','.dropdown-menu',function(){
        //alert(1);
        $(this).hide();
    });
</script>


<!--富文本编辑器需要依赖以下的外部文件-->
<link href="http://cdn.gbtags.com/twitter-bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/summernote/0.8.2/summernote.css" rel="stylesheet">
<script src="/js/bootstrap.min.js"></script>
<script src="../demo/summernote.js"></script>
<script src="http://cdn.bootcss.com/summernote/0.7.1/lang/summernote-zh-CN.min.js"></script>
<!--end-->
<style>
    body {
        background-color: #F1F2F7!important;
    }
    a {
        color: #646464;

    }
    a:hover {
        text-decoration: none;
        color: #646464;
    }
    #addnews .my-box span {
        display: inline-block;;
        width: 60px!important;
        font-size: 18px;
    }
    #addnews .my-box em {
        color: red;
    }
    #addnews .my-box>div {
        margin-top: 30px;
    }
    #addnews .my-box input,
    #addnews .my-box textarea {
        width: 600px;
        padding: 10px;
    }
    #addnews .my-box textarea {
        vertical-align: top;
    }
    #addnews .submit {
        display: inline-block;
        padding: 6px 10px;
        font-size: 18px;
        background-color: #68cacb;
        color: #fff;
        border-radius: 5px;
        margin-left: 300px;
        cursor: pointer;
    }
    #addnews .right_cont_container {
        padding: 20px;
    }
    #addnews .kingeditor {
        width: 600px;
        margin-top: 30px;
    }
    #addnews .note-editor {
        top: -27px;
        left: 63px;
    }
    .modal-body .note-image-input,
    .modal-body .note-image-url{
        width: 566px!important;
        height: 47px;
    }
</style>